package cn.kgc.springboot.http;

import lombok.Data;

import java.util.HashMap;

/**
 * @author 课工场
 * @date 2025/1/4
 * @description  统一响应结果
 *  code  ：  状态码
 *  message： 请求结果的描述
 *  data ：   响应数据
 */
@Data   //   lombook
public class ResponseResult {

    private Integer code;
    private String message;
    private HashMap<String,Object> data = new HashMap<>();


    //  业务操作成功
    public static ResponseResult success(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(0);
        responseResult.setMessage("操作成功");
        return  responseResult;
    }


    // 业务操作失败
    public static ResponseResult fail(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(110);
        responseResult.setMessage("操作失败");
        return  responseResult;
    }


    // 程序有异常
    public static ResponseResult error(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(500);
        responseResult.setMessage("程序异常...");
        return  responseResult;
    }

    // 设置响应结果的数据
    public ResponseResult data(String key,Object value){
         this.data.put(key,value);
         return this;
    }

    // 设置响应信息
    public ResponseResult message(String message){
        this.setMessage(message);
        return this;
    }

}
